package com.scp.modelo;

import com.scp.util.Aplicacao;

import android.content.ContentValues;
import android.database.Cursor;

public class Configuracao extends ModeloBase {

	private String nome;
	private String valor;
	
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getValor() {
		return valor;
	}
	public void setValor(String valor) {
		this.valor = valor;
	}
	
	public Configuracao() {
		this.setNomeTabela("Configuracoes");
		this.setColunas(new String[] {"_id", "Nome", "Valor"});
	}
	
	public boolean Gravar() {
		ContentValues values = new ContentValues();
		values.put("Nome", this.getNome());
		values.put("Valor", this.getValor());
		
		this.set_id(Aplicacao.getDB().Gravar(this.getNomeTabela(), values, "_id=?", new String[] {String.valueOf(this.get_id())}));
		
		return (this.get_id() > 0);
	}
	
	public void BuscarPorPk() {
		Cursor c = Aplicacao.getDB().Buscar(this.getNomeTabela(), this.getColunas(), "_id=?", new String[] {String.valueOf(this.get_id())});
		try {
			c.moveToFirst();
			
			this.setNome(c.getString(c.getColumnIndex("Nome")));
			this.setValor(c.getString(c.getColumnIndex("Nome")));			
		} finally {
			c.close();
		}
	}
	
}
